package com.example.docking.util;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

public class TimeRangeMap {
    public static void main(String[] args) {
        // 获取当天开始和结束时间的时间戳
        String startTime = getDayStartTime();
        String endTime = getDayEndTime();
        //Time range map: {create_start_time=1744560000000, create_end_time=1744646399999}
        // 创建一个 Map 来存储时间戳
        Map<String, String> timeRangeMap = new HashMap<>();
        timeRangeMap.put("create_start_time", startTime);
        timeRangeMap.put("create_end_time", endTime);

        // 输出结果
        System.out.println("Time range map: " + timeRangeMap);
    }

    // 获取当天的开始时间（毫秒）
    public static String getDayStartTime() {
        Calendar calendar = Calendar.getInstance();
        // 减去7天
        calendar.add(Calendar.DAY_OF_MONTH, -7);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return String.valueOf(calendar.getTime().getTime());
    }

    // 获取当天的结束时间（毫秒）
    public static String getDayEndTime() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);
        return String.valueOf(calendar.getTime().getTime());
    }

    // 获取开始时间五分钟后的时间（毫秒）
    public static String getFiveMinutesAfterStartTime() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        // 在开始时间基础上增加 5 分钟
        calendar.add(Calendar.MINUTE, 5);
        return String.valueOf(calendar.getTime().getTime());
    }


}